package org.jeecg.modules.user.cycling.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.modules.controller.UserWebSocket;
import org.jeecg.modules.user.cycling.entity.PileReq;
import org.jeecg.modules.user.cycling.service.CyclingService;
import org.jeecg.modules.utils.BikeResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Validated
@RestController
@CrossOrigin
@RequestMapping("/cycling")
@Api(value = "骑行", description = "骑行", tags = {"骑行"})
public class CyclingController {

    @Autowired
    private CyclingService cyclingService;

    /**
     *   扫码骑行
     *
     * @param
     * @return
     */
    @ApiOperation(value="扫码骑行", notes="扫码骑行")
    @PostMapping(value = "/getCycling")
    public BikeResult getCycling(@RequestBody PileReq pileReq, HttpServletRequest request) {
        return cyclingService.getCycling(pileReq,request);
    }

    /**
     *   校验车桩
     *
     * @param
     * @return
     */
    @ApiOperation(value="校验车桩", notes="校验车桩")
    @PostMapping(value = "/checkPileCode")
    public BikeResult checkPileCode(@RequestBody PileReq pileReq, HttpServletRequest request) {
        return cyclingService.checkPileCode(pileReq,request);
    }
    /**·
     *   扫码骑行
     *
     * @param
     * @return
     */
    @ApiOperation(value="aaa", notes="aaa")
    @PostMapping(value = "/aaaa")
    public void aaaa(String userId,String code,String msgTxt) {
        UserWebSocket userWebSocket = new UserWebSocket();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code",code);
            jsonObject.put("msgTxt",msgTxt);//消息内容 y n

        userWebSocket.sendOneMessage(userId,jsonObject.toJSONString());
    }


}
